﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace NG
{
    class UserProjectHandler:IUserCreatesProjectHandler
    {
        private string tableName = "[dbo].[UsernameProject]";

        public void create(User user, Project project)
        {
            DBConnect con = new DBConnect();
            string tbn = "[" + con.dbName + "]." + this.tableName;
            if (con.OpenConnection() == false)
            {
                throw new System.Exception("Couldn't connect to the Database");
            }
            string query = "INSERT INTO " + tbn + "([user],project) VALUES('" + user.username + "'," + project.ID + ");";
            SqlCommand cmd = new SqlCommand(query, con.connection);
            try
            {
                cmd.ExecuteNonQuery();
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            if (con.CloseConnection() == false)
            {
                throw new System.Exception("Couldn't discon`nect from the Database");
            }
        }


        public void delete(User user, Project project)
        {
            throw new NotImplementedException();
        }
    }
}
